const mongoose = require('mongoose');
require('dotenv').config();

const User = require('./models/User');

mongoose.connect(process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/couple_chat', {
  useNewUrlParser: true,
  useUnifiedTopology: true,
})
.then(() => console.log('✅ 已连接数据库'))
.catch((err) => console.error('❌ 数据库连接失败', err));

const seedUsers = async () => {
  try {
    await User.deleteMany(); // 清空已有数据，按需保留

    const users = await User.insertMany([
      {
        userId: "001",
        email: 'girl@example.com',
        password: '123456',
        nickname: '小可爱',
        role: 'girl'
      },
      {
        userId: "002",
        email: 'aiwarm@example.com',
        password: 'secret',
        nickname: '温柔男友',
        role: 'boy'
      },
      {
        userId: "003",
        email: 'aicool@example.com',
        password: 'secret',
        nickname: '高冷男友',
        role: 'boy'
      },
      {
        userId: "004",
        email: 'aifunny@example.com',
        password: 'secret',
        nickname: '搞笑男友',
        role: 'boy'
      }
    ]);

    console.log('✅ 插入成功：');
    users.forEach(u => console.log(`${u.nickname}: ${u._id}`));
  } catch (err) {
    console.error('❌ 插入失败:', err.message);
  } finally {
    mongoose.disconnect();
  }
};

seedUsers();
